package com.gitee.Transformation

import org.apache.flink.api.common.functions.RichMapFunction
import org.apache.flink.api.scala.ExecutionEnvironment

/*
  map和mappartition效果是一样的,但是使用外部链接mappartition要快一些,因为它可以减少链接关闭和打开次数
  留一个疑问 mapPartition怎么使用
 */
object MapAndMapPartition {
  def main(args: Array[String]): Unit = {
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    import org.apache.flink.api.scala._
    env.setParallelism(1)
    case class User(id: String, name: String)
    val lineData: DataSet[String] = env.fromElements("1,张三", "2,李四", "3,王五", "4,赵六")

    lineData.map(text=>{
      User(text.split(",")(0),text.split(",")(1))
    }).print()

    lineData.mapPartition(data=>{
      // TODO 打开连接
      data.map(text=>{
        User(text.split(",")(0),text.split(",")(1))
      })
      // TODO 关闭连接
    }).print()

  }
}
